package mall.controller;

import com.mall.entity.ResponseDTO;
//import com.mall.pojo.business.Ad;
import com.mall.pojo.goods.Category;
//import com.mall.service.business.AdService;
import com.mall.service.goods.CategoryService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
public class IndexController {

//    @DubboReference
//    private AdService adService;


    @DubboReference
    private CategoryService categoryService;

    /**
     * 网站首页
     * @return
     */
    @GetMapping("/index")
    public ResponseDTO index(Model model){
        //查询首页轮播图
//        List<Ad> lbtList = adService.findByPosition("web_index_lb");
        //查询商品分类
        List<Map> categoryList = categoryService.findCategoryTree();

        Map<String, Object> searchMap = new HashMap<>();
        searchMap.put("isShow","1");
        searchMap.put("isMenu","1");
        List<Category> indexList = categoryService.findList(searchMap);

        List<String> indexCategoryList = new ArrayList<>();
        for (Category c: indexList) {
            indexCategoryList.add(c.getName());
        }

        Map result = new HashMap<String,Object>();
//        result.put("lbt",lbtList);
        result.put("categoryList",categoryList);
        result.put("indexCategoryList",indexCategoryList);

        return ResponseDTO.success(result);
    }

}
